package light.head.dao.site;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import light.head.constant.Parm;
import light.head.enm.RESULT;
import light.head.framework.base.BaseDAO;
import light.head.framework.entity.PageBean;
import light.head.framework.utils.DateUtils;
import light.head.model.ParkAnnouncement;
import org.springframework.stereotype.Service;

/**
 * 园区公告
 */
@Service
public class ParkAnnouncementDAO extends BaseDAO<ParkAnnouncement, Serializable> {
	private static final String sql_indexlist = "SELECT pa.code, pa.title FROM ParkAnnouncement pa  WHERE pa.deleted = 0 ORDER BY pa.topTime DESC LIMIT 6";
	public RESULT findByMap(Map<String, String> map, PageBean pageBean) {
		StringBuffer hql = new StringBuffer("FROM ParkAnnouncement pa WHERE 1 = 1");
		List<Object> list = null;
		if (map != null) {
			list = new ArrayList<Object>();
			String title = map.get(Parm.TITLE);
			String time1 = map.get(Parm.TIME1);
			String time2 = map.get(Parm.TIME2);
			String deleted = map.get(Parm.DELETED);
			if (title != "" && isNotNull(title)) {
				hql.append(" AND pa.title LIKE ? ");
				list.add("%" + title + "%");
			}
			if(time1!=""&&isNotNull(time1)){
				hql.append(" AND pa.rt >= ? ");
				list.add(DateUtils.getDateByStr(time1, "yyyy-MM-dd"));
			}
			if(time2!=""&&isNotNull(time2)){
				hql.append(" AND pa.rt <= ?");
				list.add(DateUtils.getDateByStr(time2, "yyyy-MM-dd"));
			}
			if(deleted!=""&&isNotNull(deleted)){
				hql.append(" AND pa.deleted = ?");
				list.add(Boolean.parseBoolean(deleted));
			}
		}
		hql.append(" ORDER BY pa.topTime DESC");

		return findToPageBean(hql.toString(), pageBean, list);
	}
	//获取首页List
	public List<ParkAnnouncement> getIndexList(){
		return query(sql_indexlist,null,null);
	}
}
